<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('专业技术职务列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west" th:if="${showFlag}">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 人员档案
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse" th:if="${showFlag}">
                    <form id="formId">
                        <input type="hidden" id="deptId" name="deptId">
                        <input type="hidden" id="userId" name="userId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>员工姓名：</label>
                                    <input type="text" name="userName"/>
                                </li>
                                <li>
                                    <label>取得资格：</label>
                                    <select name="postName" th:with="type=${@dict.getType('basic_post_name')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>聘任资格：</label>
                                    <select name="postTitle" th:with="type=${@dict.getType('basic_post_title')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>用户类别：</label>
                                    <select name="userType" th:with="type=${@dict.getType('basic_user_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>编制情况：</label>
                                    <select name="workDuty" th:with="type=${@dict.getType('basic_work_duty')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>取得职称：</label>
                                    <select name="obtainLevel" th:with="type=${@dict.getType('basic_post_level')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>聘任职称：</label>
                                    <select name="postLevel" th:with="type=${@dict.getType('basic_post_level')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>职务级别：</label>
                                    <select name="postType" th:with="type=${@dict.getType('basic_post_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>取得方式：</label>
                                    <select name="postMode" th:with="type=${@dict.getType('basic_post_mode')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>是否默认：</label>
                                    <select name="isDefault" th:with="type=${@dict.getType('sys_yes_no')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue == 'Y'}"></option>
                                    </select>
                                </li>
                                <li class="select-time">
                                    <label>取得时间： </label>
                                    <input type="text" class="time-input" id="startTime1" placeholder="开始时间" name="params[beginTime1]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime1" placeholder="结束时间" name="params[endTime1]"/>
                                </li>
                                <li class="select-time">
                                    <label>上次聘任时间： </label>
                                    <input type="text" class="time-input" id="startTime3" placeholder="开始时间" name="params[beginTime3]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime3" placeholder="结束时间" name="params[endTime3]"/>
                                </li>
                                <li class="select-time">
                                    <label>聘任时间： </label>
                                    <input type="text" class="time-input" id="startTime2" placeholder="开始时间" name="params[beginTime2]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime2" placeholder="结束时间" name="params[endTime2]"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()" shiro:hasPermission="basic:post:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="basic:post:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="basic:post:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="basic:post:import">
                        <i class="fa fa-upload"></i> 导入
                    </a>
                    <a class="btn btn-success" onclick="downloadFile()" shiro:hasPermission="basic:post:download">
                        <i class="fa fa-download"></i> 下载
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-table-export-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('basic:post:edit')}]];
        var removeFlag = [[${@permission.hasPermi('basic:post:remove')}]];

        var postNameDatas = [[${@dict.getType('basic_post_name')}]];
        var postTitleDatas = [[${@dict.getType('basic_post_title')}]];
        var postLevelDatas = [[${@dict.getType('basic_post_level')}]];
        var postTypeDatas = [[${@dict.getType('basic_post_type')}]];
        var postModeDatas = [[${@dict.getType('basic_post_mode')}]];
        var defaultDatas = [[${@dict.getType('sys_yes_no')}]];
        var prefix = ctx + "basic/post";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryPostList();
            queryUserTree();
        });

        function queryPostList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "专业技术职务",
                showExport: true,
                exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'], // 导出的文件类型
                exportOptions: {
                    ignoreColumn: [0, 16],
                    fileName: '技术职务',    // 文件名称设置
                    mso: {
                        worksheetName: '技术职务',
                        //修复导出数字不显示为科学计数法
                        onMsoNumberFormat: function (cell, row, col) {
                            return !isNaN($(cell).text())?'\\@':'';
                        }
                    }
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'postId',
                    title: '职务id',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'userNo',
                    title: '员工工号'
                },
                {
                    field: 'userName',
                    title: '员工姓名'
                },
                {
                    field: 'postNo',
                    title: '资格证号'
                },
                {
                    field: 'postName',
                    title: '取得职务资格',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(postNameDatas, value);
                    }
                },
                {
                    field: 'obtainTime',
                    title: '取得时间',
                    sortable: true
                },
                {
                    field: 'postTitle',
                    title: '聘任职务资格',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(postTitleDatas, value);
                    }
                },
                {
                    field: 'lastEngageTime',
                    title: '上次聘任时间',
                    sortable: true
                },
                {
                    field: 'engageTime',
                    title: '聘任时间',
                    sortable: true
                },
                {
                    field: 'postType',
                    title: '职务级别',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(postTypeDatas, value);
                    }
                },
                {
                    field: 'obtainLevel',
                    title: '取得职称等级',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(postLevelDatas, value);
                    }
                },
                {
                    field: 'postLevel',
                    title: '聘任职称等级',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(postLevelDatas, value);
                    }
                },
                {
                    field: 'postMode',
                    title: '取得方式',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(postModeDatas, value);
                    }
                },
                {
                    field: 'fileUrl',
                    title: '文件路径',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'isDefault',
                    title: '是否默认',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(defaultDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.postId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        function queryUserTree()
        {
            var url = ctx + "basic/user/treeData";
            var options = {
                url: url,
                expandLevel: 1,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                var type = treeNode.type;
                var id = treeNode.id;
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                if(type == 'user'){
                    $("#userId").val(treeId);
                    $("#deptId").val('');
                }else{
                    $("#userId").val('');
                    $("#deptId").val(treeId);
                }
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryUserTree();
        });

        function add(){
            var userId = $("#userId").val();
            if(userId == undefined || userId == '') {
                $.operate.add(0);
            }else{
                $.operate.add(userId);
            }
        }

        function downloadFile(){
            var rows = $.table.selectFirstColumns();
            $.modal.confirm("确定导出所选的" + rows.length + "份技术职务材料吗？", function() {
                window.location.href = prefix + "/download?postIds=" + rows.join();
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果专业技术服务已经存在，更新这条数据。"> 是否更新已经存在的专业技术服务
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>